<template>
	<view>
		<my-goods :goodsArr="goodsArr" @nav='goodsItemClick'></my-goods>
	</view>
</template>

<script>
	import MyGoods from '@/components/my-goods/my-goods.vue';
	export default {
		components: {
			MyGoods
		},
		data() {
			return {
				goodsArr: [],
				num: 1
			}
		},
		onPullDownRefresh() {
			setTimeout(()=>{
				uni.stopPullDownRefresh();
				this.num=1
				this.goodsArr=[]
				this.getgoods()
			}, 1000);
		},
		onReachBottom() {
			console.log('下拉了')
			if (this.goodsArr.length >= 15) {
				return uni.showToast({
					title: '没有数据了',
					icon: "none"
				})
			}
			uni.showLoading({
				title: '加载中'
			})
			setInterval(() => {
				uni.hideLoading()
			}, 1000)
			this.num = 2
			this.getgoods()
		},
		onLoad() {
			this.getgoods()
		},
		methods: {
			// 获取商品详情
			async goodsItemClick(id){
				uni.navigateTo({
					url:`../shangpinxiangqing/shangpinxiangqing?id=${id}`
				})
			},
			// 获取商品
			async getgoods() {
				const data = await uni.$http.get(`/getgoods?pageindex=${this.num}`)
				console.log(data)
				this.goodsArr.push(...data.message)
				// console.log(this.goodsArr)
			},
		}
	}
</script>

<style>

</style>
